
let playerInfo = require('./playerInfo');

class RoomInfo{
    constructor(id,type) {
        this.maxPlayers = 2; //最大人数
        this.roomId = id; //房间号
        this.players = []; //玩家,存玩家的id号
        this.isHaveSeat = 1;//是否有空的座位 1是有 2是没有

        this.gameTypeZt = type;// 主题赛的类型 文体1 主球2 民族3

        for (let i = 0; i <  this.maxPlayers;i++) {
            this.players.push(null);
        }
    }

    getRoomInfo(){
        let res = {
            roomId:this.roomId,
            players: this.players,
            gameTypeZt: this.gameTypeZt
        }
        return res;
    }

    //搜索有用的空位
    search_empty_seat_inview(){
        for (let i = 0; i <  this.maxPlayers; i++) {
            if(this.players[i] == null) {
                return i;
            }
        }
        return -1;
    }

    //玩家创建了房间并入座
    do_enter_room(uid){
        let idx = this.search_empty_seat_inview();
        this.players[idx] = uid
    }
}

module.exports = RoomInfo;
